#include "skillbutton.h"
#include "playertable.h"
#include "player.h"
#include <QPainter>
#include <QStyleOption>


/*

  SKILL BUTTON SUPER CLASS

*/
SkillButton::SkillButton(QGraphicsObject *parent) :
    QGraphicsObject(parent)
{
    setAcceptHoverEvents(true);
    connect(this, SIGNAL(pressed(SkillButton*)), this, SLOT(startAskill(SkillButton*)));
}


void SkillButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){

    bool down = option->state & QStyle::State_Sunken;
    bool over = option->state & QStyle::State_MouseOver;
    if(down){
        QBrush b(QColor(Qt::white), Qt::SolidPattern);
        painter->fillRect(boundingRect(), b);
    }else if(over){
        QBrush b(QColor(Qt::black), Qt::SolidPattern);
        painter->fillRect(boundingRect(), b);
    }else{
        QBrush b(QColor(Qt::green), Qt::SolidPattern);
        painter->fillRect(boundingRect(), b);
    }
    painter->drawText(boundingRect(), Qt::AlignCenter, name());


}
QRectF SkillButton::boundingRect() const{
    int width = 60;
    int height = 20;
    return QRectF(0,0,width,height);
}

void SkillButton::access(){
    skillDialog->enter();
}
void SkillButton::mousePressEvent(QGraphicsSceneMouseEvent *event){
    emit pressed(this);
    update();
}

void SkillButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
    update();
}

void SkillButton::startAskill(SkillButton*){
    access();
}
/*


  YELLOW SKILL CLASS


*/
YellowSkillButton::YellowSkillButton(QGraphicsObject *parent, player* pl,int x, int y):
    SkillButton(parent)
{

    skillDialog = new YellowSkill(parent, pl, QPixmap(":/common/images/linmeng.jpg"));
    //the dialog should be over village tiles
    _x = x;
    _y = y;
    _Player = pl;
}

QString YellowSkillButton::name(){
    return "Y skill";
}

